home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SETBUF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  616 b   |  23 lines

  1. /*setbuf.c --- p 463 */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     FILE *infile;
  6.     char filename[81], buffer[BUFSIZ+1];
  7.     printf("Enter name of a text file: ");
  8.     gets(filename);
  9.                     /* Open the file for reading */
  10.     if ( (infile = fopen(filename, "r")) == NULL)
  11.     {
  12.         printf("fopen failed.\n");
  13.         exit(0);
  14.     }
  15.                 /* Set up a new buffer for the file */
  16.     setbuf(infile, buffer);
  17.             /* Now read in a single character -- this should fill
  18.              * up the buffer */
  19.     fgetc(infile);
  20.     buffer[BUFSIZ] = '\0';          /* Make it a C string */
  21.     printf("After reading one character from file buffer has:\n%s\n",
  22.                                 buffer);
  23. }